﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Threading;


namespace TaoBaoProject.Pages
{
  public partial class BackupDB : System.Web.UI.Page
  {
    BackDBBLL backBD = new BackDBBLL();
    public bool backDBResult = false;
    protected void Page_Load(object sender, EventArgs e)
    {
      Image1.Visible = false;
    }

    protected void imgBtnBackupData_Click(object sender, ImageClickEventArgs e)
    {
      Image1.Visible = true;
      //bool isOK = backBD.BackDB();

      Thread bk = new Thread(BackUPDBThread);
      bk.Start();
      while (bk.IsAlive)
      {
        Thread.Sleep(100);
      }
      string sqlBKSavePath = AppDomain.CurrentDomain.BaseDirectory + "UploadSqls\\";
      if (backDBResult)
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "<script>alert('备份数据库成功！已经成功备份了SQL 文件，请查看 UploadSqls 文件夹。');</script>", false);
      else
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "<script>alert('备份数据库失败！')</script>", false);
      Image1.Visible = false;
    }
    private void BackUPDBThread()
    {
      backDBResult = backBD.BackDB();
    }
  }
}